package tech.lq0.dreamaticvoyage.client.tooltip;

import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import tech.lq0.dreamaticvoyage.item.fukamizutech.material.AcidCannoli;

public class AcidCannoliTooltip implements ClientTooltipComponent {

    private final ItemStack stack;

    @Override
    public void renderImage(@NotNull Font font, int x, int y, GuiGraphics guiGraphics) {
        guiGraphics.pose().pushPose();

        if (this.stack != null && this.stack.getTag() != null) {
            if (this.stack.getTag().contains("Material")) {
                var tag = this.stack.getTag().getCompound("Material");
                var material = ItemStack.of(tag);

                guiGraphics.renderItem(material, x, y + 2);
                guiGraphics.drawString(font, material.getHoverName(), x + 20, y, 5636095);

                int count = this.stack.getTag().getInt("MaterialCount");
                guiGraphics.drawString(font, count + " / " + AcidCannoli.MAX_COUNT,
                        x + 20, y + 10, count >= AcidCannoli.MAX_COUNT ? 5635925 : 0xFFFFFF);
            }
        }

        guiGraphics.pose().popPose();
    }

    public AcidCannoliTooltip(AcidCannoliComponent tooltip) {
        this.stack = tooltip.stack();
    }

    @Override
    public int getHeight() {
        return 20;
    }

    @Override
    public int getWidth(@NotNull Font font) {
        int width = 32;
        if (this.stack != null && this.stack.getTag() != null) {
            if (this.stack.getTag().contains("Material")) {
                var tag = this.stack.getTag().getCompound("Material");
                var material = ItemStack.of(tag);
                return width + font.width(material.getHoverName());
            }
        }
        return width;
    }
}
